// 环境配置
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:path_provider/path_provider.dart';

import 'shared/services/network/http_config.dart';
import 'shared/services/network/interceptor/auth_interceptor.dart';

class EnvConfig {
  final String appTitle;
  final HttpConfig httpConfig;
  EnvConfig({
    required this.appTitle,
    required this.httpConfig,
  });
}

// 获取的配置信息
class Env {
  // 获取到当前环境
  static const appEnv = String.fromEnvironment(EnvName.envKey);
  // 开发环境
  static final HttpConfig _devHttpConfig = HttpConfig(
    pem: '''-----BEGIN CERTIFICATE-----
MIIEizCCAvOgAwIBAgIQQGQ46vgSsHF1NODj8bbaaDANBgkqhkiG9w0BAQsFADCB
iTEeMBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMS8wLQYDVQQLDCZoeUBo
dWFuZ3lpZGVNYWNCb29rLVByby5sb2NhbCAo6buE5q+FKTE2MDQGA1UEAwwtbWtj
ZXJ0IGh5QGh1YW5neWlkZU1hY0Jvb2stUHJvLmxvY2FsICjpu4Tmr4UpMB4XDTIx
MDcyOTA4NDY1M1oXDTIzMTAyOTA4NDY1M1owWjEnMCUGA1UEChMebWtjZXJ0IGRl
dmVsb3BtZW50IGNlcnRpZmljYXRlMS8wLQYDVQQLDCZoeUBodWFuZ3lpZGVNYWNC
b29rLVByby5sb2NhbCAo6buE5q+FKTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBAMYHRNHkIQXxU2MLmMzUsijGVxpqwXqwEI2UckgAM8TnKjljHOwmEKkO
CUUntJdNcVFvi5FQudavAB5nb3Kb+jdX6+VU+uhp3EcTGqVfqhjLtYSFvDcHgdpp
w6ahowrTENwmfrzZMsj16EyhUVb6rrOWgnBTpB9yXCJiE7g+3mIgOePdnnJSGbE4
yOrqh6Z8nyClXRBRR7p+afUzPVEtIgD8UwPuCfNuuOWaMpae0FVNW+Xs8oFO1WAu
hMUCEE+7Wb84rdXg71ij5XcQJ3xd5LifM+7ALjTYdj0VdHs5IFkzOTeU9XVOa+UM
VJ1bOiAaxBvTm0FpKl5fb7vwcTlMZGsCAwEAAaOBnDCBmTAOBgNVHQ8BAf8EBAMC
BaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAUmtNUZj5X5IHIO1F/
JFdloeFFYLYwUQYDVR0RBEowSIILZXhhbXBsZS5jb22CDSouZXhhbXBsZS5jb22C
DGV4YW1wbGUudGVzdIcEwKgUKocEwKgUKocQAAAAAAAAAAAAAAAAAAAAATANBgkq
hkiG9w0BAQsFAAOCAYEATkDJtPJ6ohXrisXDZ9R9NrMBzKWQCCtrjp/qyCOtnxIk
Cb3v2sUO0ENudlWzdHCh1vmdqvQBDKWjibjCehaUW2rkYdr+yDDLmugE61ty/XfN
sG2VZ3VadjqMsvW9aCEfSxucRsPNduFJ9dDbs/m7C31FArvu4QwYCYvt2E3eWbVZ
v563kkk5k78+oy0kkJsGjLMGACSANWBMHG3eIV7y6+TQ2AMm5kxApIEfju6cTtMT
y6hC/7o154TgKifYJLXot4dngvC73e9kYElBnq0RpL03oW/SQWnlUrE5yb5+OOt+
E2+94KMmg93ZBM6ydvlOz85MEjhy9XWb37PR0Z9Dvam3RTgt5AOgTYSK0+8/3PmS
b6jij60q5s62VvTEsaNJf4jRuyHShdzaRGUWNwJdqge5i9IK84wixQUJkXEgotyI
RSmIq25E4Ey3l8HTkgKXfW6EL1rUinYXuHsamZ97dE00k0XGKRjQBmSmU87Gf8KQ
3SOPJAfRwRbVlz9Bk2TD
-----END CERTIFICATE-----
''',
    connectTimeout: 10000,
    sendTimeout: 10000,
    receiveTimeout: 10000,
    baseUrl: "https://192.168.20.42:8888",
    // proxy: "192.168.20.42:5555",
    headers: {
      "os": "android"
    },
    cookiesPath:  "",
    interceptors: [AuthInterceptor()]
  );

  static final HttpConfig _uatHttpConfig = HttpConfig(
    connectTimeout: 10000,
    sendTimeout: 10000,
    receiveTimeout: 10000,
    baseUrl: "https://192.168.20.42:8888",
    headers: {
      "os": "android"
    },
    interceptors: [
      AuthInterceptor(),
    ]
  );

  static final HttpConfig _prdHttpConfig = HttpConfig(
    connectTimeout: 10000,
    sendTimeout: 10000,
    receiveTimeout: 10000,
    baseUrl: "https://192.168.20.42:8888",
    headers: {
      "os": "android"
    },
    interceptors: [AuthInterceptor()]
  );

  static final EnvConfig _devConfig = EnvConfig(
    appTitle: "debugTitle",
    httpConfig:  _devHttpConfig,
  );
  // 发布环境
  static final EnvConfig _prdConfig = EnvConfig(
    appTitle: "releaseTitle",
    httpConfig: _prdHttpConfig,
  );
  // 测试环境
  static final EnvConfig _uatConfig = EnvConfig(
    appTitle: "testTitle",
    httpConfig: _uatHttpConfig,
  );

  static EnvConfig get envConfig => _getEnvConfig();

// 根据不同环境返回对应的环境配置
  static EnvConfig _getEnvConfig() {
    switch (appEnv) {
      case EnvName.dev:
        return _devConfig;
      case EnvName.prd:
        return _prdConfig;
      case EnvName.uat:
        return _uatConfig;
      default:
        return _devConfig;
    }
  }
}

// 声明的环境
abstract class EnvName {
  // 环境key
  static const String envKey = "APP_ENV";
  // 环境value
  static const String dev = "dev";
  static const String prd = "prd";
  static const String uat = "uat";
}